package com.e7.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.e7.common.Constants;
import com.e7.common.E7Action;
import com.e7.model.Activity;
import com.e7.model.Campus;
import com.e7.model.Manor;
import com.e7.service.ActivityService;
import com.e7.service.ManorService;
import com.opensymphony.xwork2.Action;

@Component("manorAction")
public class ManorAction extends E7Action {

	private static final long serialVersionUID = -6139486272348823355L;
	private ManorService manorService;
	private ActivityService activityService;

	// client set
	private Integer id;
	private String order = Constants.OrderType.NAME;
	private Integer num = 20;
	private Integer page = 1;

	// return
	private List<Object> result;

	// private List<Manor> manors;
	// private List<Activity> activities;
	public String manorInfo() {
		Manor manor = this.manorService.getManor(this.id);
		// TODO
		this.result = new ArrayList<Object>(1);
		this.result.add(manor);
		return Action.SUCCESS;
	}

	public String allManors() {
		List<Manor> manors = this.manorService.getAllManors(this.order,
				this.page, this.num);
		// TODO check the size of manors
		this.result = new ArrayList<Object>();
		this.result.addAll(manors);
		return Action.SUCCESS;
	}

	public String allCampuses() {
		List<Campus> campuses = this.manorService.getAllCampuses(this.order,
				this.page, this.num);
		this.result = new ArrayList<Object>();
		this.result.addAll(campuses);
		return Action.SUCCESS;
	}

	public String manorsOfCampus() {
		List<Manor> manors = this.manorService.getManors(1, this.id,
				this.order, this.page, this.num);
		// TODO Auto-generated method stub
		this.result = new ArrayList<Object>();
		this.result.addAll(manors);
		return Action.SUCCESS;
	}

	public String manorsOfUniversity() {
		List<Manor> manors = this.manorService.getManors(2, this.id,
				this.order, this.page, this.num);
		// TODO Auto-generated method stub
		this.result = new ArrayList<Object>();
		this.result.addAll(manors);
		return Action.SUCCESS;
	}

	/**
	 * activities of the specified (by this.id) manor
	 * 
	 * @return
	 */
	public String activitiesOfManor() {
		List<Activity> activities = this.activityService.getActivities(this.id,
				this.order, this.page, this.num);

		// TODO Auto-generated method stub
		this.result = new ArrayList<Object>();
		this.result.addAll(activities);
		return Action.SUCCESS;
	}

	public List<Object> getResults() {
		return this.result;
	}

	// public List<Manor> getManors() {
	// return manors;
	// }
	//
	// public List<Activity> getActivities() {
	// return activities;
	// }

	public void setPage(Integer page) {
		this.page = page;
	}

	public void setNum(Integer num) {
		this.num = num;
	}
}
